package com.stox.ui.javafx.charting.model.uiunit;

import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;

import com.stox.ui.javafx.charting.model.plot.NumberPlot;

public class LineUiUnit extends NumberUiUnit {

	public LineUiUnit(Number model, NumberPlot plot, int index) {
		super(model, plot, index);
	}
	
	@Override
	public void paint() {
		if(getIndex() >= getPlot().getChart().getChartingView().getEndIndex()-1){
			return;
		}
		
		NumberUiUnit previousUiUnit = getPlot().getUiUnits().get(getIndex()+1);
		if(null == previousUiUnit.getY() || null == getY()) return;
		double previousX = previousUiUnit.getX() + previousUiUnit.getWidth()/2;
		double currentX = x + width/2;
		Canvas canvas = getPlot().getChart().getCanvas();
		GraphicsContext gc = canvas.getGraphicsContext2D();
		gc.setStroke(getColor());
		gc.setLineWidth(1);
		gc.strokeLine(previousX, previousUiUnit.getY(), currentX, getY());
	}

}
